package com.example.demo.service;

import com.example.demo.mapper.KlassMapper;
import com.example.demo.model.Klass;
import com.example.demo.repository.KlassRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class KlassService {

    @Autowired
    private KlassMapper klassMapper;
    @Autowired
    private KlassRepository klassRepository;


    public List<Klass> findAll(Klass klass) {
        if (klass.getMajor() != null || klass.getName() != null) {
            return klassMapper.findAll(klass);
        } else {
            return klassMapper.findAll(klass); //mybatis
        }

    }

    public void deleteById(String id) {
        klassMapper.deleteById(id);
    }

    public void save(Klass s) {
        klassMapper.save(s);
    }

    public Klass getReferenceById(String id) {
        return klassMapper.getReferenceById(id);
    }

    public void update(Klass s) {
        klassMapper.update(s);
    }
}
